package com.puzzlebazar.client.util;

public class GridValidityImpl {
	
	/**
	 * Make sure the provided location indicates a cell within the grid
	 * 
	 * @param loc The cell location to check
	 * @param gridSize The size of the grid to check
	 * @return true if it is within the grid, false otherwise 
	 */
	public static boolean isValidCell(Vec2i loc, Vec2i gridSize) {
		return loc.x >= 0 && loc.x < gridSize.x && loc.y >= 0 && loc.y < gridSize.y;
	}

	/**
	 * Make sure the provided location indicates a vertex within the grid
	 * 
	 * @param loc The vertex location to check
	 * @param gridSize The size of the grid to check
	 * @return true if it is within the grid, false otherwise 
	 */
	public static  boolean isValidVertex(Vec2i loc, Vec2i gridSize) {
		return loc.x >= 0 && loc.x <= gridSize.x && loc.y >= 0 && loc.y <= gridSize.y;	
	}	

	/**
	 * Make sure the provided location indicates a vertical edge within the grid
	 * 
	 * @param loc The vertical edge location to check
	 * @param gridSize The size of the grid to check
	 * @return true if it is within the grid, false otherwise 
	 */
	public static boolean isValidVerticalEdge(Vec2i loc, Vec2i gridSize) {
		return loc.x >= 0 && loc.x <= gridSize.x && loc.y >= 0 && loc.y < gridSize.y;	
	}	

	/**
	 * Make sure the provided location indicates a horizontal edge within the grid
	 * 
	 * @param loc The horizontal edge location to check
	 * @param gridSize The size of the grid to check
	 * @return true if it is within the grid, false otherwise 
	 */
	public static boolean isValidHorizontalEdge(Vec2i loc, Vec2i gridSize) {
		return loc.x >= 0 && loc.x < gridSize.x && loc.y >= 0 && loc.y <= gridSize.y;	
	}

	/**
	 * Make sure the provided rectangle of cells is within the grid
	 * 
	 * @param rect The rectangle to check (in width and height in cells)
	 * @param gridSize The size of the grid to check
	 * @return true if it is within the grid, false otherwise 
	 */
	public static boolean isValidRect(Recti rect, Vec2i gridSize) {
		return rect.x >= 0 && rect.x <= gridSize.x && rect.y >= 0 && rect.y <= gridSize.y &&
			rect.x + rect.w >= 0 && rect.x + rect.w <= gridSize.x && 
			rect.y + rect.h >= 0 && rect.y + rect.h <= gridSize.y;
	}

}
